package com.open.capacity.notice.provider;

import java.util.Optional;

import org.springframework.plugin.core.PluginRegistry;
import org.springframework.security.authentication.InternalAuthenticationServiceException;

import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class NoticeTemplateFacotoy {

	private static final String ERROR_MSG = "找不到消息code为 %s 的实现类";

	private final PluginRegistry<NoticeTemplate, String> registry;

	public NoticeTemplate getNoticeTemplate(final String code) {
		return Optional.ofNullable(registry.getPluginFor(code))
				.orElseThrow(() -> new InternalAuthenticationServiceException(StrUtil.format(ERROR_MSG, code)));

	}

}
